let gulp    = require("gulp")
let connect = require("gulp-connect");
let proxy   = require("http-proxy-middleware")
let {paths , proxyList} = require("./gulp.config");
function styles(){
    return gulp.src(paths.styles.src)
            .pipe(gulp.dest(paths.styles.dist))
            .pipe(connect.reload())
}
function html(){
    return gulp.src(paths.html.src)
            .pipe(gulp.dest(paths.html.dist))
            .pipe(connect.reload())
}
function scripts(){
    return gulp.src(paths.scripts.src)
            .pipe(gulp.dest(paths.scripts.dist))
            .pipe(connect.reload())
}
function myConnect(){
    connect.server({
        root : "./dist",
        port : 8888,
        livereload : true,
        middleware  : function(connect ,opt){
            let arr = [];
            for(let attr in proxyList){
                arr.push(proxy(attr,proxyList[attr]))
            }
            return arr;
        }
    })
}
function watch(){
    gulp.watch(paths.styles.src,styles);
    gulp.watch(paths.scripts.src,scripts);
    gulp.watch(paths.html.src,html);
}

let dev = gulp.series(gulp.parallel(myConnect , watch));

module.exports = dev ;